package com.stylefeng.guns.modular.JobHandler;

import com.stylefeng.guns.config.redis.RedisUtil;
import com.stylefeng.guns.config.zimg.ZimgClient;
import com.stylefeng.guns.modular.system.service.IArtificerMeansService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class ImageHandler {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private IArtificerMeansService artificerMeansService;

    @Resource
    private ZimgClient zimgClient;

//    @Scheduled(fixedDelayString ="1000")
//    wx   void   handleImage(){
//        List<ArtificerMeans> list=artificerMeansService.selectList(new EntityWrapper<ArtificerMeans>().isNull("base64"));
//        for (ArtificerMeans artificerMeans:list) {
//            log.info("需要转为原型图片的MD5地址为：{}",artificerMeans.getImgUrl());
//            BufferedImage  bufferedImage=zimgClient.transferImgForRoundImgage(redisUtil.get("zimg-host")+artificerMeans.getImgUrl());
//            String base64 = ImageUtil.encodeImgageToBase64(bufferedImage);
//            log.info("转为圆形图片成功!base64为：{}",base64);
//            artificerMeans.setBase64(base64);
//            artificerMeansService.updateById(artificerMeans);
//        }
//
//    }

//    wx static void main(String[] args) {
//        try {
//            // 读取图片
//            BufferedImage bi1 = ImageIO.read(new File("C:\\Users\\admin\\Pictures\\Camera Roll\\4.png"));
//            BufferedImage bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(),
//                    BufferedImage.TYPE_INT_RGB);
//            Ellipse2D.Double shape = new Ellipse2D.Double(0, 0, bi1.getWidth(), bi1
//                    .getHeight());
//            Graphics2D g2 = bi2.createGraphics();
//            g2.setBackground(Color.WHITE);
//            g2.fill(new Rectangle(bi2.getWidth(), bi2.getHeight()));
//            g2.setClip(shape);
//            //设置抗锯齿
//            g2.drawImage(bi1, 0, 0, null);
//            g2.dispose();
//            ImageIO.write(bi2, "jpg", new File("C:\\Users\\admin\\Pictures\\Camera Roll\\5.jpg"));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}
